﻿// This sample code will not work on your machine, as it is written against a "phone book" application on our intranet.
// I left it in to give you an idea on how it works.  I have not yet finished the sample.


using System.Windows.Input;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;
using Mouse = Microsoft.VisualStudio.TestTools.UITesting.Mouse;
using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
using SDWorx.ICTCorp.TestAutomationFramework.WinFormsApplication; // for start button.
using SDWorx.ICTCorp.TestAutomationFramework.WebFormsApplication;

namespace SDWorx.ICTCorp.TestAutomationFramework
{
    [CodedUITest]
    public class PhoneBookTest
    {
        [TestMethod]
        public void SearchBenjaminDeLeeuw()
        {
            // Click 'start' button
            TAF_WinWindow mUIStartWindow = new TAF_WinWindow("Start", "Button", "start", "");
            Mouse.Click(new TAF_WinButton(mUIStartWindow,"Start"));

            // Click 'Run...' menu item
            TAF_WinWindow mUIStartMenu = new TAF_WinWindow("", "ToolbarWindow32", "", "Application");
            TAF_WinMenu UiMn = new TAF_WinMenu(mUIStartMenu);
            Mouse.Click(new TAF_WinMenuItem(UiMn,"Run..."));

            // Select 'http://intranet.sd.dika.be/telefoonboekje/' in 'Open:' combo box
            TAF_WinWindow mUIRunWindow = new TAF_WinWindow("Run", "#32770", "Run", "");
            TAF_WinWindow UiRunItemWindow = new TAF_WinWindow(mUIRunWindow);
            new TAF_WinComboBox(UiRunItemWindow,"Open:").EditableItem = "http://intranet.sd.dika.be/telefoonboekje/";
            // Type '{Enter}' in 'Open:' text box
            Keyboard.SendKeys(new TAF_WinComboBox(UiRunItemWindow, "Open:"), "{enter}", ModifierKeys.None);

            // Type 'de leeuw' in 'igtxtwteSearch' text box
            TAF_BrowserWindow mUIPhoneBookWindow = new TAF_BrowserWindow("Telefoonboekje");
            TAF_HtmlFrame mUIMainFrame = new TAF_HtmlFrame(mUIPhoneBookWindow,"main", "main.aspx");
            TAF_HtmlDocument mUIMainDocument = new TAF_HtmlDocument(mUIMainFrame);
            new TAF_HtmlEdit(mUIMainDocument,"igtxtwteSearch","").Text = "De Leeuw";

            // Click 'cmdZoek' button
            Mouse.Click(new TAF_HtmlInputButton(mUIMainDocument, "cmdZoek", "cmdZoek"));

            // Verify that the results contain 'Benjamin'
            TAF_HtmlFrame mUIContentFrame = new TAF_HtmlFrame(mUIPhoneBookWindow, "contents", "contents.aspx");
            TAF_HtmlDocument mUIContentDocument = new TAF_HtmlDocument(mUIContentFrame);
            TAF_HtmlDiv mUIDIV = new TAF_HtmlDiv(mUIContentDocument, "dgAfdeling_drs", "");
            TAF_HtmlTable mUITable = new TAF_HtmlTable(mUIDIV, "", "");
            // Assert.AreEqual("Benjamin", new WebCell(mUITable, "0", "2").InnerText);  TODO: for some reason this still fails.

            // TODO Click 'De Leeuw' link
            // Mouse.Click(new WebHyperlink(new WebCell(mUITable, "0", "1"),""De Leeuw"")); // Innertext = "De Leeuw"

            // Click 'Close' button
            TAF_WinTitleBar UiBar = new TAF_WinTitleBar(mUIPhoneBookWindow);
            Mouse.Click(new TAF_WinButton(UiBar, "Close"));
        }
    }
}
